package collection;

import java.util.ArrayList;
import java.util.List;

public class SubListDemo {
    public static void main(String[] args) {
        List<Integer>list = new ArrayList<>();
        for(int i = 0;i<10;i++){
            list.add(i*10);
        }
        System.out.println("list"+list);

        //List subList(int start,int end):含头不含尾
        List<Integer>subList = list.subList(2,8);
        System.out.println("subList"+subList);

        //将子集每个元素都扩大10倍
        for (int i = 0;i< subList.size();i++){
            subList.set(i,subList.get(i)*10);
        }
        System.out.println("subList"+subList);
        //对子集的操作就是对原集合对应的元素操作
        System.out.println("list"+list);

        list.set(3,100);//将原集合下标为3的元素修改为1000
        System.out.println("list"+list);

        //原集合数据改变后，子集也跟着变了
        System.out.println("subList"+subList);

        //对子集增删后，原集跟着改
       subList.remove(0);
        System.out.println("subList:"+subList);
        System.out.println("list"+list);

        //对原集增删后，子集不能在进行操作了---因为载体变了
        list.remove(0);
        System.out.println("list:"+list);
    }
}
